package com.wallpaper.weatherwallpaper;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class SystemImageAdapter extends BaseAdapter{

	private Context mContext;  
	private Integer[] systemwallpaperIds;
	   
	public SystemImageAdapter(Context c,Integer[] wids){  
		mContext=c;
		systemwallpaperIds=wids;
		System.gc();//优化内存溢出
	}  
	
	public int getCount() {
		// TODO Auto-generated method stub
		return systemwallpaperIds.length;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null; 
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView imageview;  
		if(convertView==null)
		{  
			imageview=new ImageView(mContext);
			imageview.setLayoutParams(new GridView.LayoutParams(85, 85));
			imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
			imageview.setPadding(8,8,8,8);  
		}  
		else  
		{
			imageview=(ImageView) convertView;  
		}
		Bitmap bm=BitmapFactory.decodeResource(mContext.getResources(), systemwallpaperIds[position]);
		
		Bitmap scaledBm=Bitmap.createScaledBitmap(bm, 85, 85,true);//将原图片缩略成固定大小，优化内存溢出
		bm.recycle();//及时清理处理过的Bitmap，优化内存溢出

		imageview.setImageBitmap(scaledBm); 
		return imageview;
	}
	
	public Integer[] getSystemwallpaperIds(){
		return this.systemwallpaperIds;
	}
}
